home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7380 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: [Help] I can't find my error.
  5. Date: 25 Feb 1996 19:29:49 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4gqutt$i1f@umbc9.umbc.edu>
  8. References: <4ggvgr$1b2@aurora.engr.LaTech.edu>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. |> Could anyone please tell me why the following program won't work?
  13. |>
  14. |> *********************************************************
  15. |> /* This program will ask your name and age; and then
  16. |> will print your name and age for next year back */
  17. |> 
  18. |> #include <stdio.h>
  19. |> 
  20. |> main()
  21. |> {
  22. |>     char name;    
  23. |>     int  age, next_age; 
  24. |> 
  25. |>     printf("%s\n","Please enter your name and age: ");
  26. |>     scanf("%s%d\n", &name, &age);
  27.  
  28. Why do you use %s when you clearly have 'name' declared as a single
  29. char. So either use %c in which case we'll assume you know a lot of people
  30. with 1 letter names /* OR */ make your declaration an array of acceptable
  31. length to how long you expect the average name to be. Using 'char name[80]'
  32. should be more than enough.
  33.  
  34. |>     next_age= age + 1;
  35. |>     printf("Hi, %s ,next year, you will be %d\n", name, next_age);
  36.  
  37. Might want to add a 'return (0);' here.
  38. |> }
  39. -- 
  40. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  41.  
  42. Jonas J. Schlein  (schlein@gl.umbc.edu)
  43.